<?php
	class W_dp3_mod extends Model{
		function W_dp3_mod(){
			parent::Model();
		}
        
        function list_dp3($nip="", $where="", $order="", $ro=false) {
            if ($nip=="") {
                return "";
            } else {                                                                  
                $id_pegawai = Datum_model::getData('idspg_pegawai','pegawai','nip_baru ="'.$nip.'"');                     
                $id_pegawai = $id_pegawai!=false?$id_pegawai:Datum_model::getData('idspg_pegawai','pegawai','nip ="'.$nip.'"');                     
                $this->db->where(array('id_pegawai' => $id_pegawai));
            }
            if ($where!='') {
                $this->db->where($where);
            }
            if ($order == "") {
                $this->db->order_by('tahun asc');
            } else {
                $this->db->order_by($order);
            }
            $q = $this->db->get('dp3');

            $s = "
              <table id=\"scrollable\" width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" class=\"tbl\">
                <thead>
                  <tr>
                    <th>No</th>
                    
                    <th>Tahun </th>
                    <th>Pejabat Penilai </th>
                    <th>Atasan Pejabat</th>
                    <th>Nilai</th>
                    
                    ";
            if ($ro==false) {
                $s .= " <th colspan='2'> Aksi </th>";
            }
            $s .= "</tr></thead><tbody>";
			$i = 1;

            $this->load->model('Datum_model');
            foreach($q->result() as $row) {
                if ($i % 2 == 1) {
                    $kelas = "event2";
                } else {
                    $kelas = "event";
                }

               // $pegawai = Datum_model::getData('nip', 'pegawai', array('idspg_pegawai' => $row->id_pegawai));
                
                
                $s .= "
              <tr class=\"$kelas\" id=\"row-".$row->idspg_dp3."\" >
                <td><div align=\"right\">$i.&nbsp;&nbsp;&nbsp;</div></td>
                
                <td>".$row->tahun."</td>
                <td>".$row->pejabat_penilai."</td>
                <td>".$row->atasan_pejabat_penilai."</td>
                <td>".$row->nilai."</td>
               
    
                ";
                if ($ro==false) {
                    $s .= "
                    <td><div align='center'> <a href='".base_url()."index.php/dp3/form_edit/".$row->idspg_dp3."' title=\"Ubah Data\" class=\"edit\"><img src='".base_url()."images/edit.gif' border='0'></a></div></td>   
                    <td><div align='center'><a href=\"javascript:deleteRow(".$row->idspg_dp3.")\"><img src='".base_url()."images/del.gif' border='0'></a></div></td>";
                }
                $s .= "
              </tr>";

                $i++;
            }
            $s .= "</tbody></table>";
            return $s;
        }

        function entry_dp3($form_id, $form_action, $arr=array()) {
        	
        	
        	$ret = "
			<form action='$form_action' method='post' name='dp3' id='$form_id'>

                <fieldset >
                 <table class='formTabel' border='0' align='center' cellpadding='5' cellspacing='1'>
                  <tr>
                    <td class='kolom' valign='top'>NIP </td>
                    <td valign='top'>:</td>
                    <td valign='top'>
                    
                      <input name='nip' type='text' id='nip' value='".(isset($arr['nip'])?$arr['nip']:$this->session->userdata('nip'))."' />     
                      
                       </td>
                  </tr>   
                 <tr>
                    <td class='kolom' valign='top'>Tahun </td>
                    <td valign='top'>:</td>
                    <td valign='top'>
                      <input name='tahun' type='text' id='tahun' value='".(isset($arr['tahun'])?$arr['tahun']:"")."'  />
                       </td>
                  </tr>
                  <tr>
                    <td valign='top'>Pejabat Penilai</td>
                    <td valign='top'>:</td>
                    <td valign='top'>
                      <input name='pejabat_penilai' type='text' id='pejabat_penilai' value='".(isset($arr['pejabat_penilai'])?$arr['pejabat_penilai']:"")."'  />
                     </td>
                  </tr>
                  <tr>
                    <td valign='top'>Atasan Pejabat Penilai</td>
                    <td valign='top'>:</td>
                    <td valign='top'>
                      <input name='atasan_pejabat_penilai' type='text' id='atasan_pejabat_penilai' value='".(isset($arr['atasan_pejabat_penilai'])?$arr['atasan_pejabat_penilai']:"")."'>
                     </td>
                  </tr>
                  <tr>
                    <td valign='top'>Nilai</td>
                    <td valign='top'>:</td>
                    <td valign='top'>
                      <input name='nilai' type='text' id='nilai' value='".(isset($arr['nilai'])?$arr['nilai']:"")."'>
                     </td>
                  </tr>
                  <tr>
                    <td valign='top'>&nbsp;</td>
                    <td valign='top'>&nbsp;</td>
                    <td valign='top'>
                      <input class=\"tombol\" type=\"button\" name=\"btn_kembali\" id=\"btn_kembali\" value=\"<< Kembali\" />
                  <input class=\"tombol\" type=\"submit\" name=\"button\" id=\"button\" value=\"   Simpan   \" />
                     </td>
                  </tr>
                </table>
               
                </fieldset>

                </form>
			  ";
        	
        	return $ret;
        }

        function simpan($arr, $is_update=false, $id='') {
            if (!$is_update) {
                $this->db->insert('dp3', $arr);
            } else {
                $this->db->where('idspg_dp3', $id);
                $this->db->update('dp3', $arr);
            }
        }
        
	}
?>